package tests.page;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description: 奖品管理页面
 * User: Spider-Man
 * Date: 2025-09-21
 * Time: 17:21
 */
public class PrizeManagementPage {

    /**
     * 活动列表
     * @throws IOException
     */
    public void activityListPage() throws IOException {
        WebDriver driver = Utils.createDriver();
        driver.findElement(By.cssSelector("body > div.cont-box > div.sidebar > ul > li:nth-child(2) > ul > li:nth-child(1) > a")).click();

        WebElement element = driver.findElement(By.cssSelector("body > div.header-box > div.user-box > div > span"));
        String expect = element.getText();
        assert expect.equals("退出");
        element = driver.findElement(By.cssSelector("body > div > h2"));
        expect = element.getText();
        assert expect.equals("奖品列表");

        element = driver.findElement(By.cssSelector("body > div > div.table-box > table > thead > tr > th:nth-child(1)"));
        expect = element.getText();
        assert expect.equals("奖品id");

        element = driver.findElement(By.cssSelector("body > div > div.table-box > table > thead > tr > th:nth-child(2)"));
        expect = element.getText();
        assert expect.equals("奖品图");

        element = driver.findElement(By.cssSelector("body > div > div.table-box > table > thead > tr > th:nth-child(3)"));
        expect = element.getText();
        assert expect.equals("奖品名");

        element = driver.findElement(By.cssSelector("body > div > div.table-box > table > thead > tr > th:nth-child(4)"));
        expect = element.getText();
        assert expect.equals("奖品描述");

        element = driver.findElement(By.cssSelector("body > div > div.table-box > table > thead > tr > th:nth-child(5)"));
        expect = element.getText();
        assert expect.equals("奖品价值");

        Utils.getScreenShot(Thread.currentThread().getName());

    }

    /**
     * 奖品创建
     */
    public void createPrizePage () throws IOException {
        WebDriver driver = Utils.createDriver();
        driver.findElement(By.cssSelector("body > div.cont-box > div.sidebar > ul > li:nth-child(2) > ul > li:nth-child(2) > a")).click();//进入创建

        WebElement element = driver.findElement(By.cssSelector("body > div > h2"));
        String expect = element.getText();
        assert expect.equals("开始创建奖品");

        element = driver.findElement(By.cssSelector("#prizeRows > div > div:nth-child(1) > label"));
        expect = element.getText();
        assert expect.equals("奖品名称");
        element = driver.findElement(By.cssSelector("#prizeName"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入奖品名称");

        element = driver.findElement(By.cssSelector("#prizeRows > div > div:nth-child(2) > label"));
        expect = element.getText();
        assert expect.equals("奖品图片");
        driver.findElement(By.cssSelector("#prizeImageUrl"));


        element = driver.findElement(By.cssSelector("#prizeRows > div > div:nth-child(3) > label"));
        expect = element.getText();
        assert expect.equals("奖品价格");
        element = driver.findElement(By.cssSelector("#price"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("请输入奖品价格");

        element = driver.findElement(By.cssSelector("#prizeRows > div > div:nth-child(4) > label"));
        expect = element.getText();
        assert expect.equals("奖品描述");
        element = driver.findElement(By.cssSelector("#description"));
        expect = element.getAttribute("placeholder");
        assert expect.equals("");

        element = driver.findElement(By.cssSelector("body > div > button"));
        expect = element.getText();
        assert expect.equals("创建奖品");

        Utils.getScreenShot(Thread.currentThread().getName());
    }
}
